#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <iostream>
using namespace std;

#define TRACE(x...) 
#define PRINT(x...) TRACE(printf(x))
#define WATCH(x) TRACE(cout << #x << " = " << x << endl)

#define rep(i,n) for (int i=0; i<n; i++)
#define repi(i, a, b) for (int i=a; i<b; i++)

#define f first
#define s second
#define mp make_pair

#define ll long long
#define INF 0x3f3f3f3f
#define NINF 0xc0c0c0c0

#define sqr(x) ((x)*(x))
int n;
int k;
char mod[5][5];
char canvas[300][300];
int nk;

void dfs(int sz, int i, int j, int c, char col) {
	if (c>k) return;	
	PRINT("%d\n", sz);
//x	int div=sz/n;

	repi(a, i, i+sz) {
		repi(b, j, j+sz) {
			canvas[a][b]=col;
		}
	}

	if (col=='*') return;

	TRACE(
		rep(it,nk) {
			rep(jt,nk) printf("%c", canvas[it][jt]);
			printf("\n");
		}
	)

	rep(it, n) {
		rep(jt, n) dfs(sz/n, (sz/n)*it+i, (sz/n)*jt+j, c+1, mod[it][jt]);
	}
}

int main() {
	freopen("input.txt", "r", stdin);	
	freopen("output.txt", "w", stdout);

	scanf("%d %d", &n, &k);
	rep(i,n) scanf(" %s", mod[i]);	

	TRACE(
		rep(i,n) {
			rep(j,n) printf("%c", mod[i][j]);
			printf("\n");
		}
	)

	nk=1;
	rep(i,k) nk*=n;

	PRINT("n^k = %d\n",nk);
	int div;
	int prevdiv=1;
	int fl;	

	dfs(nk, 0, 0, 0, '.');

	rep(i,nk){
		rep(j,nk) printf("%c", canvas[i][j]);
		printf("\n");
	}

	return 0;
}
